package cn.zzp.basic.service.impl;

import cn.zzp.basic.mapper.BaseMapper;
import cn.zzp.basic.query.BaseQuery;
import cn.zzp.basic.service.BaseService;
import cn.zzp.basic.util.PageList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName BaseServiceImpl
 * @Description
 * @Author 祝志鹏
 * @Date 2022/7/20 16:16
 */
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements BaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;

    /**
     * 根据id查询数据
     * @param id
     * @return
     */
    @Override
    public T queryById(Long id) {
        return  baseMapper.queryById(id);
    }

    /**
     * 查询所有
     * @return
     */
    @Override
    public List<T> queryAll() {
        return baseMapper.queryAll();
    }

    /**
     * 添加部门
     * @param t
     */
    @Transactional
    @Override
    public void add(T t) {
        baseMapper.add(t);
    }

    /**
     * 修改部门
     * @param t
     */
    @Transactional
    @Override
    public void update(T t) {
        baseMapper.update(t);
    }

    /**
     * 根据id删除数据
     * @param id
     */
    @Transactional
    @Override
    public void delete(Long id) {
        baseMapper.delete(id);
    }

    /**
     * 分页查询
     * @param query 分页查询参数
     * @return totals 总条数---rows 当前页数据
     */
    @Override
    public PageList<T> pageQuery(BaseQuery query) {

        Integer count = baseMapper.queryCount(query);
        List<T> rows = baseMapper.pageQuery(query);

        return new PageList<T>(count,rows);
    }

    @Override
    public void patchDel(List<Long> ids) {
        baseMapper.patchDel(ids);
    }
}
